package control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Aluno;
import model.DAOAluno;
import model.DAOTurma;
import model.Turma;

/**
 * Servlet implementation class MatricularAlunoServlet
 */
public class MatricularAlunoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MatricularAlunoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int id_al = Integer.parseInt(request.getParameter("id_al"));
		int id_tur = Integer.parseInt(request.getParameter("id_tur"));
		DAOTurma dao_tur = new DAOTurma();
		DAOAluno dao_alu = new DAOAluno();
		Aluno a = dao_alu.find(id_al);
		dao_tur.begin();
		Turma t = dao_tur.find(id_tur);
		t.addAluno(a);
		dao_tur.merge(t);
		dao_tur.commit();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
